<!DOCTYPE html>
<html>
<!--包含公共文件-->
{include file='head'}

<!--bootstrap分页-->
<link rel="stylesheet" type="text/css" href="{$staticAdmin}dist/css/bootstrap.min.css">

<!--  这个标签内添加需要的内容  -->
<section class="rt_wrap content mCustomScrollbar">
    <div class="rt_content" name="div1">
        <div class="page_title">
            <h2 class="fl">会员列表</h2>
            <a href="{$webSite}admin/user/increase.html" class="fr top_rt_btn add_icon">添加新会员</a>
        </div>
        <section class="mtb">
            <select class="select" id="sel0">
                <option value="0">会员等级</option>
                {foreach $userLevel as $lev}
                <option value="{$lev['level_id']}">{$lev['level_name']}</option>
                {/foreach}

            </select>
            <input type="text" class="textbox textbox_225" name="put" placeholder="输入会员号/手机/电子邮件查询..."/>
            <input type="button" value="查询" class="group_btn" name="btn"/>

            <span class="tip"></span>
        </section>
        <table class="table" name="tb1">
            <tr>
                <th>Id</th>
                <th>会员头像</th>
                <th>会员账号</th>
                <th>手机号码</th>
                <th>电子邮件</th>
                <th>验证</th>
                <th>会员等级</th>
                <th>账户余额</th>
                <!--<th>冻结资金</th>-->
                <th>操作</th>
            </tr>

            <!--遍历用户信息-->
            <!--  {foreach $user as $u}
              <tr name="tr1">
               <td class="center">{$u['uid']}</td>
               <td class="center"><img src="{$webSite}{$u['pic']}" width="50" height="50"/></td>
               <td>{$u['username']}</td>
               <td class="center">{$u['phone']}</td>
               <td class="center">{$u['email']}</td>
               <td class="center"><a title="已验证" class="link_icon">&#89;</a></td>
               {foreach $userLevel as $type}
                 {if $type['level_id'] == $u['level_id']}
               <td class="center">{$type['level_name']}</td>
                 {/if}
               {/foreach}
               <td class="center">
                <strong class="rmb_icon">{$u['grade']}</strong>
               </td>
              &lt;!&ndash; <td class="center">
                <strong class="rmb_icon">59.00</strong>
               </td>&ndash;&gt;
               <td class="center">
                <a href="{$webSite}admin/user/detail.html?uid={$u['uid']}" title="编辑" class="link_icon">&#101;</a>
                <a href="{$webSite}admin/user/receive.html?uid={$u['uid']}" title="回收" class="link_icon">&#100;</a>
               </td>
              </tr>
              {/foreach}-->
        </table>
        <!--分页-->
        <aside class="paging" name="page">
             <!--{$userPage}-->
        </aside>

    </div>
</section>
</body>
</html>
<script>
    $(function () {
        $('[name=btn]').click(function () {

            var $oLev = $('#sel0').val();
            // console.log($oLev);
            var $oName = $('[name=put]').val().replace(/(^\s*)|(\s*$)/g, "");

            //邮箱规则
            //var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;

            //若为空
            if ($oName.length == 0) {

                $('.tip').html('查询条件不能为空').css('color','red');

                //若为邮箱
            }
            /* else if(myreg.exec($oName)) {

                $('.tip').html('邮箱');
                $.post('sel',{email:$oName,level:$oLev},success,'json');

                //若为手机
            } else if((/^1[34578]\d{9}$/.test($oName))) {

                $('.tip').html('手机号');
                $.post('sel',{phone:$oName,level:$oLev},success,'json');

            } else {

                //按用户名处理
                $('.tip').html('用户名');
                $.post('sel',{username:$oName,level:$oLev},success,'json');
            }*/

            $.post('find',{page:1},success,'json');
            //alert(22222);

        });

        //回调函数
        function success(data)
        {
            //console.log(data);

            switch (data.status) {

                /*       case 1:

                           $('.tip').html('您查询的邮箱如下').css('color','green');
                           break;
                       case 2:

                           $('.tip').html(data.tip).css('color','red');
                           break;

                       case 3:
                           $('.tip').html('您查询的手机号如下').css('color','green');

                           break;
                       case 4:
                           $('.tip').html(data.tip).css('color','red');
                           break;
                       case 5:

                           $('.tip').html('您查询的用户名如下').css('color','green');
                           break;
                       case 6:

                           $('.tip').html('data.tip').css('color','red');
                           break;*/
                case 11:

                    //console.log(data.res);

                    //获取数据
                    var $oRes = data.res;
                    var $oSite = data.webSite;
                    var $oLevel = data.level;
                    var $page = data.page;
                    var $oPage = data.pageUrl;
                    $oPage = $oPage.replace('\\"','');
                    $oPage = $oPage.replace('/"','/');
                    $oPage = $oPage.replace('//','/');
                    $oPage = $oPage.replace('find','lists');
                    //console.log($oPage);
                    //console.log($page);
                    var $arr = [];  //存放变量的数组
                    var $num = 0;
                    var flag = false;
                    var $tr = null;

                    if (!flag) {

                        //清空
                        $('.tr1').remove();
                        flag = true;

                        //批量创建表格行
                        var $total = ($oRes.length/8);
                        for (var i = 0; i < $total; i++) {

                            //添加节点
                            $('[name=tb1]').append('<tr class="tr1"></tr>');
                            $num++;
                            //console.log($num);

                            //下标
                            for (var m = 0; m < 8; m++) {
                                $arr.push(($num-1)*8 *$page+m);
                            }

                            //console.log($arr);
                            //添加子节点td
                            $('.tr1').eq(i).append('<td class="center">'+ $oRes[$arr.shift()]['uid'] +'</td>');
                            $('.tr1').eq(i).append('<td class="center"><img src='+  $oSite + $oRes[$arr.shift()]['pic'] + ' width="50" height="50"/></td>');
                            $('.tr1').eq(i).append('<td class="center" >'+ $oRes[$arr.shift()]['username'] +'</td>');
                            $('.tr1').eq(i).append('<td class="center" >'+ $oRes[$arr.shift()]['phone'] + '</td>');
                            $('.tr1').eq(i).append('<td class="center" >'+ $oRes[$arr.shift()]['email']+'</td>');
                            $('.tr1').eq(i).append('<td class="center"><a title='+ $oRes[$arr.shift()]['is_active'] +' class="link_icon">&#89;</a></td>');
                            $('.tr1').eq(i).append('<td class="center">'+ $oRes[$arr.shift()]['level_id'] +'</td>');
                            $('.tr1').eq(i).append('<td class="center"><strong class="rmb_icon">'+ $oRes[$arr.shift()]['grade'] +'</strong></td>&ndash;&gt;');
                            $('.tr1').eq(i).append('<td class="center"><a href="" title="编辑" class="link_icon">&#101;</a><a href="" title="回收" class="link_icon">&#100;</a></td>');
                            //console.log($arr);
                        }
                    }

                    //给a标签的href加上页面url
                   // console.log($oPage);
                    $('[name=page]').append($oPage);

                    $('[name=page] > a').eq(0).css('href','javascript:tiao('+ $oPage +');');
                    $('[name=page] > a').eq(1).css('href','javascript:tiao('+ $oPage +');');
                    $('[name=page] > a').eq(2).css('href','javascript:tiao('+ $oPage +');');
                    $('[name=page] > a').eq(3).css('href','javascript:tiao('+ $oPage +');');
console.log($('[name=page] > a'));

                    break;

                case 12:
                    alert(data.tip);
                    break;

            }
        }

        function tiao($p)
        {
            $.get('find',{page:$p},success,'json');
        }

    });


</script>
